#pragma once
#include <QFile>
#include <string>
#include <QObject>
#include "ferrylog.h"

class Ferryfs;
extern Ferryfs* ferryfs;

class Ferryfs : public QObject {
    Q_OBJECT
public:

    Ferryfs(QString mountpoint);

    Q_INVOKABLE bool createFerryfs(const QString &path);

    Q_INVOKABLE void writeDeviceIDToDB();

    Q_INVOKABLE QString readDeviceIDFromDB();

    Q_INVOKABLE void writePasswordToDB(const QString password);

    Q_INVOKABLE QString readPasswordFromDB();

    Q_INVOKABLE void writeKeyToDB();

    Q_INVOKABLE unsigned int* readKeyFromDB();

    bool writeAuditInfoToDB();

    bool readAuditInfoFromDB();

    bool readAllAuditInfoFromDB();

    Q_INVOKABLE static const bool isFerryfs(const QString &path);

    QString getDefaultPassword();

    const QByteArray encryptQByteArray(const QByteArray &plaintext);

    const QByteArray decryptQByteArray(const QByteArray &ciphertext);

    int PKCS7(unsigned char *pucData, unsigned long ulDataLen, unsigned char pucPaddingData[16]);

    unsigned int* qByteArrayToUnsignedInt(QByteArray source);

    QByteArray unsignedIntToQByteArray(unsigned int* des, int datasize);

    Q_INVOKABLE bool connectUdiskDB(QString connection);

    Q_INVOKABLE bool connectBuildDB(QString connection);

    Q_INVOKABLE void closeDB();

    bool PostAuditInfo(QString usbnumber, int readcount, int writecount, QString insertionTime, QString lastreadtime, QString lastwritetime, int areaid, int userid, QString removaltime, int installedsp, int deptid, QString departmentname, QString areaname, QString macIp, QString computerIp);

    QString getConfigIpAddress();

    QString getIpAddress();

    QString mountpoint;

private:
    QString getIp();

    QString getMac();

    QString getTime();


};
